#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll x, y, c[7];
void solve(){
cin >> x >> y;
for(int i=1;i<=6;i++) cin >> c[i];
ll B=y-x,A=y-B;
ll r1=(A<0?c[4]:c[1])*abs(A)+(B<0?c[5]:c[2])*abs(B);
B=x-y,A=x-B;
ll r2=(A<0?c[4]:c[1])*abs(A)+(B<0?c[3]:c[6])*abs(B);
A=x,B=y;
ll r3=(A<0?c[3]:c[6])*abs(A)+(B<0?c[5]:c[2])*abs(B);
cout<<min({r1,r2,r3});
}
int main()
{
int t;
cin >> t;
while(t--){
solve();
cout << "\n";
}
}
702C - Cellular Network | 1672C - Unequal Array |
1706C - Qpwoeirut And The City | 1697A - Parkway Walk |
1505B - DMCA | 478B - Random Teams |
1705C - Mark and His Unfinished Essay | 1401C - Mere Array |
1613B - Absent Remainder | 1536B - Prinzessin der Verurteilung |
1699B - Almost Ternary Matrix | 1545A - AquaMoon and Strange Sort |
538B - Quasi Binary | 424A - Squats |
1703A - YES or YES | 494A - Treasure |
48B - Land Lot | 835A - Key races |
1622C - Set or Decrease | 1682A - Palindromic Indices |
903C - Boxes Packing | 887A - Div 64 |
755B - PolandBall and Game | 808B - Average Sleep Time |
1515E - Phoenix and Computers | 1552B - Running for Gold |
994A - Fingerprints | 1221C - Perfect Team |
1709C - Recover an RBS | 378A - Playing with Dice |